# -*- coding:utf-8 -*-
class Solution:
    def Permutation(self, ss):
        # write code here
        ss = list(ss)
        # print(ss)
        if not ss:
            return []
        if len(ss) == 1:
            # print('return len == 1 is {}'.format(ss))
            return ss
        res_sum = []
        for i in range(len(ss)):
            input = ss[:]
            input.pop(i)
            # print('input is {}'.format(input))
            res = self.Permutation(input)
            # print('res is {}'.format(res))
            for j in range(len(res)):

                res[j] = ss[i] + res[j]
                # print('res[j] is {}'.format(res[j]))

            res_sum.extend(res)
        # print('res_sum is {}'.format(res_sum))
        return sorted(set(res_sum))# 最后要有排序



test = Solution()
print(test.Permutation('aa'))